from django.template import RequestContext
from django.shortcuts import render_to_response
from django.core.context_processors import csrf
from django.http import HttpResponse

def index(request):
    c = {}
    c.update(csrf(request))

    if request.method == 'POST':
        data = {
            'price' : request.POST['price'],
            'quantity' : request.POST['quantity'],
            'cookie' : request.COOKIES.get('Apple'),
        }

        if 'color' in request.POST:
            data['color'] = request.POST['color']

        response = render_to_response('Lab4/post-result.html', data)
        return response
    elif request.method == 'GET':
        response = render_to_response('Lab4/index.html',c)
        response.set_cookie('Apple', 'you\'re being watched. TROLOLOLOLOL')

        return response
    else:
        return HttpResponse("WTFBBQ")

def get(request):
    c = {}
    c.update(csrf(request))

    if 'price' in request.GET and 'quantity' in request.GET:
        data = {
            'price' : request.GET['price'],
            'quantity' : request.GET['quantity'],
            'cookie' : request.COOKIES.get('Apple'),
        }

        response = render_to_response('Lab4/get-result.html', data)
    else:
        response = render_to_response('Lab4/get.html',c)
        response.set_cookie('Apple', 'you\'re being watched. TROLOLOLOLOL')

    return response